//保存到草稿
$('.saveContent').on('click', function () {

		var blogTitle = $('.title').val();
		var blogTags = $('.tags').val();

		var blogContent = UE.getEditor('editor').execCommand("getlocaldata");

		$.ajax({
				type: 'POST',
				dataType: 'json',
				url: 'http://localhost:3000/blogs/save',
				beforeSend: function (xhr) {
						xhr.setRequestHeader('X-CSRF-Token', $('meta[name="csrf-token"]').attr('content'))
				},
				data: {
						title: blogTitle,
						tags: blogTags,
						content: blogContent
				},
				success: function (data) {

				}
		})
});


//评论提交
$('.submitComment').on('click', function () {
		var comment_content = UE.getEditor('editor').getContent();
		var blog_id = $('#blog_id').val();

		$.ajax({
				type: 'POST',
				url: '/comments/',
				beforeSend: function (xhr) {
						xhr.setRequestHeader('X-CSRF-Token', $('meta[name="csrf-token"]').attr('content'))
				},
				data: {
						blog_id: blog_id,
						content: comment_content
				},
				success: function (data) {
						if (data.code == '200') {
								var $commentUl = $("#comments ul");
								var count = parseInt($commentUl.attr("count")) + 1;
							  $commentUl.append("<li>" + count +"楼"+ data.content.content + "</li>");
								$commentUl.attr("count",count);
								UE.getEditor('editor').setContent('');
						}
						else {
								alert(data.msg);
						}
				},
				error: function (e) {
				}
		})
});